<?php
class myDoctrineIndexedTable extends Doctrine_Table
{
	/**
	 * Get lucene query response
	 * @param unknown_type $query
	 */
	public function getForLuceneQuery($query)
	{
		// Find hits
		$hits = $this->getLuceneIndex()->find($query);
		// Get list of id
		$pks = array();
		foreach($hits as $hit)
			$pks[] = $hit->pk;
		// Return empty array for empty list
		if(empty($pks))
			return array();
		// Return result limit query
		$q = $this->createQuery()->whereIn('id', $pks)->limit(20);
		// Return result
		return $q->execute();
	}
	/**
	 * Get lucene index file
	 */
	public function getLuceneIndex()
	{
		ProjectConfiguration::registerZend();
		if(file_exists($index = $this->getLuceneIndexFile()))
			return Zend_Search_Lucene::open($index);
		return Zend_Search_Lucene::create($index);
	}
	/**
	 * Get lucene index file path
	 */
	public function getLuceneIndexFile()
	{
		return sfConfig::get('sf_data_dir') . "/".$this->getTableName().".index";
	}
}
